package com.efrei.uchat.client.gui.view;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

public class LoginRequestTab extends JPanel {

	private static final long serialVersionUID = -7633246316902751278L;
	private JLabel lblLogin;
	private JTextField txtLogin;
	private JButton btnSubmit;
	
	public LoginRequestTab() {
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{123, 152, 0};
		gridBagLayout.rowHeights = new int[]{16, 0, 0};
		gridBagLayout.columnWeights = new double[]{1.0, 1.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		this.lblLogin = new JLabel("Login : ");
		this.lblLogin.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_lblLogin = new GridBagConstraints();
		gbc_lblLogin.anchor = GridBagConstraints.EAST;
		gbc_lblLogin.insets = new Insets(0, 0, 5, 5);
		gbc_lblLogin.gridx = 0;
		gbc_lblLogin.gridy = 0;
		add(this.lblLogin, gbc_lblLogin);
		
		this.txtLogin = new JTextField();
		GridBagConstraints gbc_txtLogin = new GridBagConstraints();
		gbc_txtLogin.anchor = GridBagConstraints.WEST;
		gbc_txtLogin.insets = new Insets(0, 0, 5, 0);
		gbc_txtLogin.gridx = 1;
		gbc_txtLogin.gridy = 0;
		add(this.txtLogin, gbc_txtLogin);
		this.txtLogin.setColumns(10);
		
		this.btnSubmit = new JButton("Submit");
		this.btnSubmit.setHorizontalAlignment(SwingConstants.CENTER);
		GridBagConstraints gbc_btnSubmit = new GridBagConstraints();
		gbc_btnSubmit.anchor = GridBagConstraints.CENTER;
		gbc_btnSubmit.gridwidth = 2;
		gbc_btnSubmit.gridx = 0;
		gbc_btnSubmit.gridy = 1;
		add(this.btnSubmit, gbc_btnSubmit);
	}
	
	public LoginRequestTab addController(ActionListener controller) {
		btnSubmit.addActionListener(controller);
		return this;
	}

	public JTextField getTxtLogin() {
		return txtLogin;
	}

	public JButton getBtnSubmit() {
		return btnSubmit;
	}
}
